#include "sceneNode.h"

sceneNode::sceneNode(string n) {
	name = n;
	D3DXMatrixIdentity(&objectMatrix);
}

sceneNode::~sceneNode()
{
	/*
	if(name != "root") {
		//mesh->Discard(D3DX10_MESH_DISCARD_DEVICE_BUFFERS);
		//mesh->Release();
	}
	*/
}

string sceneNode::getName()
{
	return name;
}

D3DXMATRIX sceneNode::getMatrix()
{
	return objectMatrix;
}

void sceneNode::setMatrix(D3DXMATRIX matrix)
{
	objectMatrix = matrix;
}

ID3DX10Mesh* sceneNode::getMesh()
{
	return mesh;
}

void sceneNode::setMesh(ID3DX10Mesh* gMesh)
{
	mesh = gMesh;
}

int sceneNode::addChild(string n)
{
	children.push_back(n);
	return children.size() - 1;

}

void sceneNode::removeChild(string n)
{
	for (int i=0; i<(int)children.size(); i++)
		if (children[i] == n) {
			children.erase(children.begin()+i);
			break;
		}
}

void sceneNode::removeChild(int i)
{
	children.erase(children.begin()+i);
}
/*
void sceneNode::removeChild(string n)
{
	for (int i=0; i<(int)children.size(); i++)
		if (children[i]->getName() == n) {
			children.erase(children.begin()+i);
			break;
		}
}
*/
vector<string>* sceneNode::getChildren()
{
	return &children;
}

bool sceneNode::isChild(string n)
{
	for (int i=0; i<(int)children.size(); i++)
		if (children[i] == n) {
			return true;
		}
	return false;
}
/*
bool sceneNode::isChild(string n)
{
	for (int i=0; i<(int)children.size(); i++)
		if (children[i]->getName() == n) {
			return true;
		}
	return false;
}
*/
int sceneNode::childCount() {
	return children.size();
}

void sceneNode::draw()
{
	mesh->DrawSubset(0);
}